package com.dc.designPattern._18_memento.extend.extend1;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.SneakyThrows;

/**
 * Description: 备忘录模式扩展_原始角色
 * @author: gdc
 * @date: 2021/7/8
 * @version 1.0
 */
@Data
@AllArgsConstructor
public class Originator implements Cloneable {

    /**
     * 状态
     */
    private String state;

    /**
     * 创建一个备忘录
     * @return              备忘录对象
     */
    public Originator createMemento() {
        return this.clone();
    }

    /**
     * 通过备忘录对象回复原来的状态
     * @param originator    备忘录对象
     */
    public void restoreMemento(Originator originator) {
        this.state = originator.getState();
    }

    @SneakyThrows
    @Override
    protected Originator clone() {
        return (Originator) super.clone();
    }
}
